package com.android.camera.one;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

import com.android.camera.debug.Log;

import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CaptureRequest;

public class CameraCharacteristicsExtend {
private static final Log.Tag TAG = new Log.Tag("CameraCharacteristicsExtend");
	
	private static Constructor mCameraCharacteristicsConstructor;
	
	private static void initialize() {
		if (mCameraCharacteristicsConstructor == null) {
			try {
	    		Class<?> nmCameraCharacteristicsClass = Class.forName(CaptureRequest.Key.class.getName());
	    		mCameraCharacteristicsConstructor = nmCameraCharacteristicsClass.getConstructor(String.class, Class.class);
	    	} catch (Exception ex) {
	    		Log.d(TAG, ""+ex.toString());
	    	}
		}
	}

	public static <T> CameraCharacteristics.Key<T> getKey(String key, Class<T> clazz) 
			throws InstantiationException, IllegalAccessException, 
					IllegalArgumentException, InvocationTargetException {
		initialize();
		return (CameraCharacteristics.Key<T>)mCameraCharacteristicsConstructor
				.newInstance(key, clazz);
	}
}
